package com.heart.house.web.controller;

import com.heart.house.biz.service.HouseService;
import com.heart.house.biz.service.RecommandService;
import com.heart.house.common.model.House;
import com.heart.house.common.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 首页配置
 *
 * @author Luo Zhen
 * @create 2019-06-27 14:18
 */
@Controller
public class HomePageController {

    @Autowired
    private RecommandService recommandService;
    @Autowired
    private HouseService houseService;

    @RequestMapping("index")
    public String index(ModelMap modelMap) {
        // 查出最热十条
        List<House> list = recommandService.getLastest();
        House query = new House();
        query.setSort("create_time");
        // 查出最新五条
        List<House> houses = houseService.queryAndSetImg(query, PageParams.build(5, 1));

        modelMap.put("recomHouses", list);
        modelMap.put("houseList", houses);
        return "homepage/index";
    }

    @RequestMapping("")
    public String home() {
        return "redirect:/index";
    }

}
